from collections import Callable


def Template(template_file, request, *args):
    from starlette.templating import Jinja2Templates
    from FastApi.Config import TEMPLATES_FILE_PATH
    return Jinja2Templates(directory=TEMPLATES_FILE_PATH).TemplateResponse(template_file,
                                                                           {"request": request, "data": args})


def Error(code: int, reason: str):
    return {"status": False, "code": code, "reason": reason}


def Success(data, message: str = ""):
    return {"status": True, "code": 200, "payload": data, "msg": message}


def Result(res_data, suc_message: str = "获取成功", code=200, reason="", _callable: Callable = None):
    return Success(res_data, suc_message) if res_data else Error(code, reason)
